<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
        // 每5分钟检查一次订单自动化任务
        $schedule->command('orders:automation --timeout=30')
            ->everyFiveMinutes()
            ->withoutOverlapping()
            ->runInBackground();
            
        // 每小时检查长时间未发货订单
        $schedule->command('orders:automation --timeout=60')
            ->hourly()
            ->withoutOverlapping()
            ->runInBackground();
            
        // 每10分钟检查未支付订单，自动取消超过30分钟的订单
        $schedule->command('orders:cancel-unpaid --minutes=30')
            ->everyTenMinutes()
            ->withoutOverlapping()
            ->runInBackground();
            
        // 每30分钟更新购物车价格
        $schedule->command('cart:update-prices')
            ->everyThirtyMinutes()
            ->withoutOverlapping()
            ->runInBackground();
            
        // 每天清理过期通知
        $schedule->command('notifications:clean')
            ->daily()
            ->withoutOverlapping()
            ->runInBackground();
            
        // 每天凌晨2点处理过期优惠券
        $schedule->command('coupons:expire')
            ->dailyAt('02:00')
            ->withoutOverlapping()
            ->runInBackground();
            
        // 每天凌晨3点自动确认超时的换货送达
        $schedule->command('after-sales:auto-confirm-delivery --days=7')
            ->dailyAt('03:00')
            ->withoutOverlapping()
            ->runInBackground();
    }

    /**
     * Register the commands for the application.
     */
    protected function commands(): void
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
